#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<string>
#include<iostream>
using std::vector;
using std::string;
using std::cout;
using std::endl;
#include"HuffmanTree.hpp"

struct ByteInfo
{
	unsigned char _byte;
	size_t _frequency;
	string _strcode;
	ByteInfo(size_t frequency = 0)
		:_frequency(frequency)
	{}
	ByteInfo operator+(const ByteInfo& x)const
	{
		return ByteInfo(_frequency + x._frequency);
	}
	bool operator>(const ByteInfo& x)const
	{
		return _frequency > x._frequency;
	}
	bool operator!=(const ByteInfo& x)const
	{
		return _frequency != x._frequency;
	}
	bool operator==(const ByteInfo& x)const
	{
		return _frequency == x._frequency;
	}
};

class HM_Compress
{
public:
	HM_Compress();
	void HuffmanCompress(const string& filepath);
	void HuffmanUNCompress(const string& filepath);

private:
	void GetHuffmanCode(HuffmanTreeNode<ByteInfo>* root);
	void WriteHeadInfo(const string& filepath,FILE* pw);
	string GetFilePostfix(const string& filepath);
	void GetLine(FILE* pr,string& strinfo);

	vector<ByteInfo> _FileInfo;
};
